package com.sxt.sys.controller;


import com.sxt.sys.domain.Reply;
import com.sxt.sys.service.ReplyService;
import com.sxt.sys.utils.ResultObj;
import com.sxt.sys.vo.ReplyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cr
 * @since 2019-04-29
 */
@RestController
public class ReplyController {
    @Autowired
    private ReplyService replyService;

    @RequestMapping("/insert/reply")
    public ResultObj insert(ReplyVo replyVo){
        replyVo.setCreatedate(new Date());
        Integer code=1;
        String msg="";
        try {
            Integer info = replyService.insert(replyVo);
            code = info;
            msg = info > 0 ?"评论成功":"评论失败";
        } catch (Exception e) {
            code = 0;
            msg = "评论失败";
        }
        return new ResultObj(code , msg);
    }

    @RequestMapping("/queryAll/reply")
    public List<ReplyVo> queryAll(Integer topicid){
        List<ReplyVo> r = replyService.queryAll(topicid);

        return r;
    }
}

